﻿using System;
using System.IO;
using System.Linq;

namespace myWinForm.Temp.Trash
{
    public class Folder
    {
        /// <summary>
        /// 一个很叼的递归lambda表达式
        /// </summary>
        /// <param name="foldername"></param>
        /// <returns></returns>
        public static long CalculateFolderSize(string foldername)
        {
            if (Directory.Exists(foldername) == false)
            {
                throw  new DirectoryNotFoundException("Directory not found");
            }

            DirectoryInfo rootDir = new DirectoryInfo(foldername);
            DirectoryInfo[] childDirs = rootDir.GetDirectories();
            FileInfo[] files = rootDir.GetFiles();

            return files.Sum(t => t.Length) + childDirs.Sum(t => CalculateFolderSize(t.FullName));
        }

        


        public static int GetRandomInt()
        {
            Random rd = new Random();
            return rd.Next();
        }
    }
}